<?php $header=$this->action('ZfcAdmin\Controller\AdminController', 'headerAction');
	  $baseUrl = $header->headerarray['baseUrl'];
?>
<?php if(isset($_SESSION['admin'])){?>
<center>
	<head>
			<?php if(isset($_GET['offer_id']) && $_GET['offer_id']!=""){?>
			<h1>Edit Offer</h1>
			<?}else{?>
			<h1>Add Offer</h1>
			<?}?>
	</head><br/>
	<form id="add_offer_form" name="add_offer_form" method="post" action="">
		Offer Name: <input type="" name="offer_name" 
		value="<? if(isset($this->offer_details->offer_name) &&	$this->offer_details->offer_name!=""){echo $this->offer_details->offer_name;}else{}?>"
		id="offer_name" placeholder="Please enter offer name"><br/><br/>				
		Offer for Amount: <input type="text" name="offer_amount"
		value="<? if(isset($this->offer_details->offer_amount) && $this->offer_details->offer_amount!=""){echo $this->offer_details->offer_amount;}else{}?>" id="offer_amount" placeholder="Please enter offer amount">
		<br/><br/>
		Discount percentage: <input type="text" name="offer_discount"
		value="<? if(isset($this->offer_details->percent_discount) && $this->offer_details->percent_discount!=""){echo $this->offer_details->percent_discount;}else{}?>" id="offer_discount" placeholder="Please enter offer discount percentage">
		<br/><br/>
		Offer Expires: 
		<? if(isset($this->offer_details->offer_expries) && $this->offer_details->offer_expries!=""){ 
		if($this->offer_details->offer_expries=='1'){?>
			<input type="checkbox" checked="checked" id="exp_check" onClick="return checkExpiryStatus();" name="exp_check" value="1">
		<?}else if($this->offer_details->offer_expries=='0'){?>
			<input type="checkbox" id="exp_check" onClick="return checkExpiryStatus();" name="exp_check" value="0">
		<?}}else{?>
			<input type="checkbox" id="exp_check" name="exp_check" onClick="return checkExpiryStatus();" value="0">
		<?}?><br/><br/>
		<div id="show_hide_dp">
		Offer Start date:<input type="text" id="start_date" name="start_date" value="<? if(isset($this->offer_details->starting_date) && $this->offer_details->starting_date!=""){ echo $this->offer_details->starting_date;}else{}?>"><br><br/>
		Offer end date:<input type="text" id="end_date" name="end_date" value="<? if(isset($this->offer_details->ending_date) && $this->offer_details->ending_date!=""){ echo $this->offer_details->ending_date;}else{}?>"><br><br/>
		</div>
		<a href="<? echo $baseUrl.'admin/offer-lists'?>">Back</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="btn_offer" name="btn_offer" value="Save" onClick="return add_offers();">
		<input type="hidden" id="hid_offer_id" name="hid_offer_id" value="<? if(isset($this->offer_details->offer_id) && $this->offer_details->offer_id!=""){echo $this->offer_details->offer_id;}else{}?>">
	</form>
</center>
<script>
	$( document ).ready(function() {
		$("#start_date").datepicker({
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:9999',
			numberOfMonths: 1,
			onSelect: function(selected) {
			var date1 = $('#start_date').datepicker('getDate');
			var date = new Date( Date.parse( date1 ) );
			date.setDate( date.getDate() + 1 );
			var newDate = date.toDateString();
			newDate = new Date( Date.parse( newDate ) );
			$('#end_date').datepicker("option","minDate",newDate);
			}
		});		
		$("#end_date").datepicker({
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:9999',
			numberOfMonths: 1,
			onSelect: function(selected) {
			   $("#start_date").datepicker("option","maxDate", selected)
			}
		});  
		checkExpiryStatus();	
	});
	function checkExpiryStatus(){
		if(document.getElementById("exp_check").checked == false){
			$("#exp_check").val(0);
			$("#show_hide_dp").hide();
		}else{
			$("#exp_check").val(1);
			$("#show_hide_dp").show();
		}		
	}
</script>
<? } else {?>
<script>
	window.location=ADMIN_BASE_URL+'admin';
</script>
<?}?>

